<template>
	<div class="mine">
		<div class="box">
			<div class="hearderBox">
				<div class="hearderBoxIcon" @click="goBack">
					<img src="../../assets/images/fanhuijiantou.png" alt="">
				</div>
				{{$t('indexTitle.title125')}}
			</div>
			<div class="jineBox" v-if="!isShowLoading">
				<div class="jineBoxTitle">
					{{$t('indexTitle.title132')}}
				</div>
				<div class="jineBoxNum">
					<span v-if="allMoney">{{allMoney}}</span>
					<span v-if="!allMoney">{{info.money||0.00}}</span>
					<img @click="refresh()" :class="showloading ? 'loading':''" src="../../assets/images/shuaxinTow.png"
						alt="">
				</div>
			</div>
			<div class="qianbaoListBox" v-if="!isShowLoading">
				<div class="qianbaoIt" v-for="(it,index) in walletlist" :key="index">
					<div class="qianbaoItTitle">
						{{it.name}}
					</div>
					<div class="qianbaoItNum" v-if="it.money != '未开通'">
						<span v-if="it.moneyTow||it.moneyTow==0">{{it.moneyTow}}</span>
						<div v-if="!it.moneyTow&&it.moneyTow!=0" class="nrc-loading active "></div>
					</div>
					<div class="qianbaoItNumTow" v-else>
						{{it.money}}
					</div>
				</div>

			</div>
		</div>
		<loadingThree v-if="isShowLoading"></loadingThree>
		<loadingFour :msgText="msgTextTow" v-if="isShowLoadingTeow" @closeGuanbiTow="closeGuanbi"></loadingFour>
		<!-- <div class="buttons">
			<img src="../../assets/images/xiaoxi.png" alt="" />
		</div> -->
	</div>
</template>

<script>
	import {
		mywallets,
		userinfo,
		check
	} from "../../utils/api.js"
	import loadingThree from '../../components/loadingThree.vue';
	import loadingFour from '../../components/loadingFour.vue';
	export default {
		data() {
			return {
				close: true,
				walletlist: [],
				info: [],
				showloading: false,
				isShowLoading: true,
				allMoney: 0.00,
				msgTextTow: "",
				isShowLoadingTeow: false
			}
		},
		components: {
			loadingThree,
			loadingFour
		},
		created() {},
		mounted() {
			this.getuserinfo()
			this.getmywallet()
		},
		methods: {
			closeGuanbi(e) {
				this.isShowLoadingTeow = false;
			},
			refresh() {
				let that = this;
				this.isShowLoading = true;
				this.showloading = true;
				setTimeout(function() {
					that.showloading = false
				}, 3000)
				this.allMoney = 0.00;
				// this.getuserinfo()
				this.getmywallet()
			},
			getuserinfo() {
				this.info = [];
				userinfo().then((res) => {
					if (res.status.errorCode == 0) {
						this.info = res.data
					} else if (res.status.errorCode == 401) {
						console.log('401')
					} else {
						// this.$message.error(res.status.msg);
						this.msgTextTow = res.status.msg;
						this.isShowLoadingTeow = true;
						setTimeout(() => {
							this.isShowLoadingTeow = false;
						}, 2000)
						// this.$message({
						// 	showClose: true,
						// 	message: res.status.msg,
						// 	type: 'error'
						// });
					}
				}).catch((err) => {
					console.log(err, 'err')
				});
			},
			getmywallet() {
				let walletlistTow = []
				mywallets().then((res) => {
					if (res.status.errorCode == 0) {
						walletlistTow = res.data;
						// this.walletlist = res.data
						walletlistTow.forEach((item, index) => {
							if (item.money != '未开通') {
								item.moneyTow = null;
								let data = {
									"api_id": item.id
								}
								check(data).then((res) => {
									if (res.status.errorCode == 0) {
										console.log(item.moneyTow)
										item.moneyTow = res.data.balance;
										this.allMoney = (Number(this.allMoney) + Number(item
											.moneyTow)).toFixed(2);
									} else {
										// this.$message.error(res.status.msg);
										this.msgTextTow = res.status.msg;
										this.isShowLoadingTeow = true;
										setTimeout(() => {
											this.isShowLoadingTeow = false;
										}, 2000)
										// this.$message({
										// 	showClose: true,
										// 	message: res.status.msg,
										// 	type: 'error'
										// });
									}
								}).catch((err) => {
									console.log(err, 'err')
								});
							}
						})
						this.walletlist = walletlistTow;
						this.isShowLoading = false;
					} else {
						// this.$message.error(res.status.msg);
						this.msgTextTow = res.status.msg;
						this.isShowLoadingTeow = true;
						setTimeout(() => {
							this.isShowLoadingTeow = false;
						}, 2000)
						// this.$message({
						// 	showClose: true,
						// 	message: res.status.msg,
						// 	type: 'error'
						// });
					}
				}).catch((err) => {
					console.log(err, 'err')
				});
			},
			goBack() {
				this.$router.go(-1)
			}
		}
	}
</script>

<style scoped>
	* {
		box-sizing: border-box;
	}

	.mine {
		height: 90vh;
		overflow-y: auto;
		overflow-x: hidden;
		padding-top: calc(constant(safe-area-inset-top) + 0px);
		padding-top: calc(env(safe-area-inset-top) + 0px);
		padding-bottom: calc(constant(safe-area-inset-bottom) + 85px);
		padding-bottom: calc(env(safe-area-inset-bottom) + 85px);
		box-sizing: border-box;
		position: fixed;
		z-index: 1;
		-webkit-overflow-scrolling: touch;
		width: 100%;
	}

	.nrc-loading.active {
		display: block;
		margin: 0 auto;
	}

	.nrc-loading {
		animation: loading-spinner 1s linear infinite;
		border-color: #666 transparent transparent #666;
		border-radius: 10px;
		border-style: solid;
		border-width: 2px;
		height: 14px;
		right: 15px;
		top: 15px;
		width: 14px;
		z-index: 2000;
	}

	@keyframes loading-spinner {
		0% {
			transform: rotate(0deg);
		}

		100% {
			transform: rotate(1turn);
		}
	}

	.box {
		background-color: #ffffff;
		display: flex;
		flex-direction: column;
		/* min-height: 100vh; */
	}

	.buttons {
		position: fixed;
		bottom: 10%;
		right: 10px;
		background-color: #99D2E3;
		width: 60px;
		height: 60px;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.buttons img {
		width: 32px;
		height: 32px;
	}


	.hearderBox {
		width: 100%;
		height: 45px;
		background-color: #fff;
		position: fixed;
		top: 0;
		line-height: 45px;
		text-align: center;
		font-size: 20px;
		color: #545658;
		box-shadow: inset 0 -1px 0 #ececec;
		left: 0;
		overflow: hidden;
		z-index: 99;
		font-weight: 300;
	}

	.hearderBoxIcon {
		width: 50px;
		position: fixed;
		top: 3px;
		left: 0px;
	}

	.hearderBoxIcon img {
		width: 20px;
		height: 20px;
	}

	.jineBox {
		width: 100%;
		margin-top: 70px;
		text-align: center;
	}

	.jineBoxTitle {
		width: 100%;
		color: #939698;
		font-size: 16px;
		margin-bottom: 5px;
	}

	.jineBoxNum {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #3b3d3e;
		font-size: 24px;
		font-weight: 500;
	}

	.jineBoxNum img {
		width: 18px;
		height: 18px;
		transform: rotate(90deg);
	}

	.jineBoxNum img.loading {
		animation: turn 1.5s linear;
	}

	@keyframes turn {
		0% {
			transform: rotate(0deg);
		}

		33% {
			transform: rotate(180deg);
		}

		66% {
			transform: rotate(360deg);
		}

		100% {
			transform: rotate(540deg);
		}
	}

	.qianbaoListBox {
		width: 90%;
		margin: 15px auto;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.qianbaoIt {
		align-items: center;
		border: 1px solid #ececec;
		border-radius: 5px;
		display: flex;
		flex-direction: column;
		height: 63px;
		margin: 0 1% 10px;
		width: 48%;
	}

	.qianbaoIt>div {
		align-items: center;
		box-sizing: border-box;
		color: #545658;
		display: flex;
		font-size: 14px;
		justify-content: center;
		width: 100%;
	}

	.qianbaoItTitle {
		background-color: #fafafc;
		border-bottom: 1px solid #ececec;
		height: 27px;
		font-weight: 300;
	}

	.qianbaoItNum {
		font-weight: 500;
		height: 35px;
	}

	.qianbaoItNumTow {
		height: 35px;
		color: #ffa600 !important;
	}
</style>